package com.tbit.uqbike.service.business.impl;

import com.tbit.uqbike.object.pojo.Park;
import com.tbit.uqbike.service.business.ParkService;
import com.tbit.uqbike.webmanager.dao.core.ParkDao;
import com.tbit.uqbike.webmanager.dao.log.ParkLogDao;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.Date;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

@Service("parkService")
public class ParkServiceImpl implements ParkService {
    @Autowired
    private ParkDao parkDao;
    @Autowired
    private ParkLogDao parkLogDao;

    @Override
    public List<Park> queryPage(List<Integer> userIds, Integer machineId, Long startTime, Long endTime, Integer rowCount, Integer pageNO) {
        Map<String, Object> params = new HashMap<String, Object>();
        params.put("userIds", userIds);
        params.put("machineId", machineId);
        params.put("startTime", new Date(startTime));
        params.put("endTime", new Date(endTime));
        params.put("start", (pageNO - 1) * rowCount);
        params.put("rowCount", rowCount);

        return parkLogDao.queryPage(params);
    }

    @Override
    public Integer queryCount(List<Integer> userIds, Integer machineId, Long startTime, Long endTime) {
        Map<String, Object> params = new HashMap<String, Object>();
        params.put("userIds", userIds);
        params.put("machineId", machineId);
        params.put("startTime", new Date(startTime));
        params.put("endTime", new Date(endTime));

        return parkLogDao.queryCount(params);
    }

    @Override
    public Park getByMachineId(Integer machineId) {
        return parkDao.getByMachineId(machineId);
    }

    @Override
    public void delByUserId(Integer userId) {
        parkDao.delByUserId(userId);
    }

    @Override
    public void addLog(Park park) {
        parkLogDao.insert(park);
    }

}  